home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr05 / ddeexamp.zip / STATUS.C < prev    next >
C/C++ Source or Header  |  1993-07-08  |  3KB  |  139 lines

  1. /*
  2.     status.c
  3.  
  4.     Functions to support the status window
  5.  
  6. */
  7.  
  8. #include <windows.h>
  9.  
  10. //
  11. // Constants
  12. //
  13.  
  14. #define MAXLISTLINES    100     // max list lines we keep
  15.  
  16. //
  17. // Global data
  18. //
  19.  
  20. HWND hwndStatus;
  21.  
  22. //
  23. // function to add a string to the end of the status list
  24. //
  25.  
  26. void cdecl Status(LPSTR lpFormat, ...) 
  27. {
  28.     int i;
  29.     char buf[256];
  30.  
  31.     //
  32.     // format the string
  33.     //
  34.  
  35.     wvsprintf(buf, lpFormat, (LPSTR)(&lpFormat+1));
  36.  
  37.     //
  38.     // stop the listbox repaints while we mess with it
  39.     //
  40.  
  41.     SendMessage(hwndStatus, WM_SETREDRAW, (WPARAM) FALSE, (LPARAM) 0);
  42.  
  43.     //
  44.     // get the item count
  45.     //
  46.  
  47.     i = (int) SendMessage(hwndStatus, LB_GETCOUNT, (WPARAM) 0, (LPARAM) 0);
  48.     if (i == LB_ERR) i = 0;
  49.  
  50.     //
  51.     // scrub a few if we have too many
  52.     //
  53.  
  54.     while (i >= MAXLISTLINES) {
  55.         SendMessage(hwndStatus, LB_DELETESTRING, (WPARAM) 0, (LPARAM) 0);
  56.         i--;
  57.     }
  58.  
  59.     //
  60.     // add the new one on at the end and scroll it into view
  61.     //
  62.  
  63.     i = (int) SendMessage(hwndStatus, LB_ADDSTRING, (WPARAM) 0, (LPARAM) (LPSTR) buf);
  64.     SendMessage(hwndStatus, LB_SETCURSEL, (WPARAM) i, (LPARAM) 0);
  65.  
  66.     //
  67.     // enable the repaint now
  68.     //
  69.  
  70.     SendMessage(hwndStatus, WM_SETREDRAW, (WPARAM) TRUE, (LPARAM) 0);
  71. }
  72.  
  73. //
  74. // Measure an item in our status listbox
  75. //
  76.  
  77. void MeasureStatusItem(HWND hWnd, LPMEASUREITEMSTRUCT lpMIS)
  78. {
  79.     TEXTMETRIC tm;
  80.     HDC hDC;
  81.  
  82.  
  83.     hDC = GetDC(hWnd);
  84.     GetTextMetrics(hDC, &tm);
  85.     ReleaseDC(hWnd, hDC);
  86.     lpMIS->itemHeight = tm.tmHeight;
  87. }
  88.  
  89. //
  90. // Display an item in one of our owner draw list boxes
  91. //
  92.  
  93. void DrawStatusItem(HWND hWnd, LPDRAWITEMSTRUCT lpDI)
  94. {
  95.     HBRUSH hbrBkGnd;
  96.     RECT rc;
  97.     HDC hDC;
  98.     char buf[256];
  99.     
  100.     hDC = lpDI->hDC;
  101.     rc = lpDI->rcItem;
  102.  
  103.     switch (lpDI->itemAction) {
  104.  
  105.     case ODA_SELECT:
  106.     case ODA_DRAWENTIRE:
  107.  
  108.         //
  109.         // erase the rectangle
  110.         //
  111.  
  112.         hbrBkGnd = CreateSolidBrush(GetSysColor(COLOR_WINDOW));
  113.         FillRect(hDC, &rc, hbrBkGnd);
  114.         DeleteObject(hbrBkGnd);
  115.  
  116.             //
  117.             // show the text in our standard font
  118.             //
  119.     
  120.             SetBkMode(hDC, TRANSPARENT);
  121.     
  122.             SendMessage(lpDI->hwndItem, 
  123.                         LB_GETTEXT, 
  124.                         lpDI->itemID, 
  125.                         (LPARAM)(LPSTR)buf);
  126.  
  127.             ExtTextOut(hDC, 
  128.                        rc.left+2, rc.top,
  129.                        ETO_CLIPPED,
  130.                        &rc, 
  131.                        buf,
  132.                        lstrlen(buf), 
  133.                        NULL);
  134.     
  135.         break;
  136.     
  137.     }
  138. }
  139.